package cn.tedu.ivos.user.contoller;

import cn.tedu.ivos.base.response.JsonResult;
import cn.tedu.ivos.user.pojo.dto.UserQuery;
import cn.tedu.ivos.user.pojo.dto.UserSaveParam;
import cn.tedu.ivos.user.pojo.vo.UserVO;
import cn.tedu.ivos.user.service.UserService;
import cn.tedu.ivos.user.pojo.dto.UserLoginParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/v1/user")
public class UserController {
    @Autowired
    UserService userService;
    @PostMapping("/login")
    public JsonResult login(@RequestBody UserLoginParam userLoginParam){
        log.debug("用户登录:{}",userLoginParam);
        UserVO login = userService.login(userLoginParam);

        return JsonResult.ok(login);
    }
    @PostMapping("/save")
    public JsonResult save(UserSaveParam userSaveParam){
        log.debug("保存用户: {}",userSaveParam);
        userService.save(userSaveParam);
        return JsonResult.ok();
    }
    @GetMapping("/select")
    public JsonResult selects(UserQuery userQuery){
        log.debug("查询用户: {}",userQuery);
        List<UserVO> userVOS = userService.selectUser(userQuery);
        log.debug("结果: {}",userVOS);
        return JsonResult.ok(userVOS);
    }
    @PostMapping("/update/password/{id}")
    public JsonResult resetPassword(@PathVariable Long id){
        log.debug("重置密码: {}",id);
        userService.rsetpassword(id);
        return JsonResult.ok();
    }
    @PostMapping("/update/status/{userId}/{status}")
    public JsonResult updateStatus(@PathVariable Long userId,@PathVariable String status){
        log.debug("修改用户状态: {}",userId);
        userService.updateStatus(userId,status);
        return JsonResult.ok();
    }
    @PostMapping("/delete/{id}")
    public JsonResult deleteUser(@PathVariable Long id){
        log.debug("删除用户: {}",id);
        userService.deletUser(id);
        return JsonResult.ok();
    }
    @GetMapping("/select/audit/{parentId}")
    public JsonResult selectAudit(@PathVariable Long parentId){
        log.debug("查询直属领导: {}",parentId);
        List<UserVO> list = userService.selectParentUser(parentId);
        log.debug("结果: {}",list);
        return JsonResult.ok(list);
    }
}
